package com.sample.snl.frontend.LexicalAnalysis;

public class InIdState extends State {
    Automaton automaton;

    public InIdState(Automaton a) {
        this.automaton = a;
    }

    @Override
    void HandleCharacter(int ch) {
        ////LexicalAnalyser.LOG.trace("In InId state.");
        if (automaton.isAlphabetic(ch) || automaton.isDigit(ch)) {
            automaton.setState(automaton.InIdState);
        } else {
            //LexicalAnalyser.LOG.trace("The current character does not belong to:{}({})", automaton.displayChar(ch), ch);
            automaton.unGetChar(automaton.stringBuilder.charAt(automaton.stringBuilder.length() - 1));
            automaton.token = new Token(LexicalAnalyser.line, LexicalAnalyser.column, TokenType.ID, automaton.stringBuilder.substring(0, automaton.stringBuilder.length() - 1));
            //LexicalAnalyser.LOG.debug("Recognized Token:" + automaton.token);
            automaton.token.checkKeyWords();
            automaton.gotToken = true;
        }
    }
}
